import axios  from "axios";
import config from '@/config/config.js';
const baseUrl = "http://localhost:8089"
let produceRequest={
    getProcess(process,page,limit,callBack){
        let url = baseUrl + "/process/list?page="+page+"&limit="+limit;
        if (process){

            if (process.processId!=null&&process.processId!=""){
                url +="&processId="+process.processId
            }
            if (process.processName!=null&&process.processName!=""){
                url+="&processName="+process.processName
            }
            if (process.processStatus!=null&&process.processStatus!=""){
                url+="&processStatus="+process.processStatus
            }

        }
        axios.get(url)
            .then(res=>{
                // 回调函数是从外面传入的，我们要将我们请求得到的结果传回到回调函数中.
                // 由于axiso会对结果进行一个封装，所以我们这里传入回调函数的数据直接就是res.data
                // 我们在外面获取的数据就是我们后端响应的数据本身。
                callBack(res.data);
            })
        console.log(url)
    },
    addProcess(process,callBack){
        let url = baseUrl +"/process/add"

        axios.post(url,process)
            .then(res=>{
                callBack(res.data);
            })
    },
    getRandom(callBack){
        let url = config.proBaseUrl +"/process/getRd"

        axios.get(url)
            .then(res=>{
                callBack(res.data);
            })
    },
    getModify(processRelId,callBack){
        let url = config.proBaseUrl +"/process/getMP?processRelId="+processRelId

        axios.get(url)
            .then(res=>{
                callBack(res.data);
            })
    },
    putModify(process,callBack){
        let url = config.proBaseUrl +"/process/modifyProcess"

        axios.put(url,process)
            .then(res=>{
                callBack(res.data);
            })
    },
    deleteProcess(processRelId,callBack){
        let url = config.proBaseUrl +"/process/delete?processRelId="+processRelId

        axios.delete(url)
            .then(res=>{
                callBack(res.data);
            })
    },
    deleteAllProcess(processes,callBack){
        let url = config.proBaseUrl +"/process/deleteAll"

        axios.post(url,processes)
            .then(res=>{
                callBack(res.data);
            })
    },
    getOperate(operateProcessRelId,page,limit,callBack){
        let url = config.proBaseUrl +"/operate/getByRelId?page="+page+"&limit="+limit+"&operateProcessRelId="+operateProcessRelId

        axios.get(url)
            .then(res=>{
                callBack(res.data);
            })
    },
    addOperate(operate,callBack){
        let url = config.proBaseUrl +"/operate/addOperate"

        axios.post(url,operate)
            .then(res=>{
                callBack(res.data);
            })
    },
    getPrimaryOperate(operateRelId,callBack){
        let url = config.proBaseUrl +"/operate/getPrimaryOperate?operateRelId="+operateRelId

        axios.get(url)
            .then(res=>{
                callBack(res.data);
            })
    },
    primaryOperate(operate,callBack){
        let url = config.proBaseUrl +"/operate/primaryOperate"

        axios.put(url,operate)
            .then(res=>{
                callBack(res.data);
            })
    },
    deleteOneOperate(operateRelId,callBack){
        let url = config.proBaseUrl +"/operate/deleteOne?operateRelId="+operateRelId

        axios.delete(url)
            .then(res=>{
                callBack(res.data);
            })
    },
    deleteChooseOperate(operates,callBack){
        let url = config.proBaseUrl +"/operate/deleteChoose"

        axios.post(url,operates)
            .then(res=>{
                callBack(res.data);
            })
    },exportOperate(operateProcessRelId,page=1,limit=10){
        // 拼接url
        let url = config.proBaseUrl + "/operate/export?page="+page+"&limit="+limit+"&operateProcessRelId="+operateProcessRelId

        // 通过超链接请求即可
        location.href = url;
    },
}

export default produceRequest;
